﻿using System.Web.Mvc;
using Gola.VN.Scb.Web.Common.Entities;
using Gola.VN.Scb.Web.Common.Models;
using Gola.VN.Scb.Web.Presentation.Helpers;
using Gola.VN.Scb.Web.Presentation.Models;

namespace Gola.VN.Scb.Web.Presentation.Controllers
{
    public class CategoryController : Controller
    {
        public ActionResult Display(int id, string keyword = "")
        {
            // ViewData["CloudData"] = CategoryService.GetCloudCategory(id); //todo: replaced by ngocbv
            ViewData["CloudData"] = MainService.GetInstant().CategoryService.GetCloudCategory(id);
            // var category = CategoryService.GetCategoryById(id); //todo: replaced by id
            CategoryEntity category = MainService.GetInstant().CategoryService.GetCategoryById(id);
            var models = new UICategoriesModels
                             {
                                 CategoryTitle = category.Name,
                                 // Categories = CategoryService.LeftPanelData,//todo: replace by ngocbv
                                 Categories = MainService.GetInstant().CategoryService.LeftPanelData,
                                 // Subcategories = CategoryService.GetSubcategoris(id),//todo: replace by ngocbv
                                 Subcategories = MainService.GetInstant().CategoryService.GetSubcategories(id),
                                 //Navigartion = CategoryService.GetNavigateData(id) //toto: replace by ngocbv
                                 Navigartion = MainService.GetInstant().CategoryService.GetNavigateData(id)
                             };
            // ViewData["Navigation"] = CategoryService.GetNavigateData(id); //todo: replace by ngocbv
            ViewData["Navigation"] = models.Navigartion;
            ViewData["Title"] = Utilities.GetTitle(category.Name);
            if (!string.IsNullOrEmpty(keyword))
            {
                MainService.GetInstant().SearchHistoryService.UpdateSearchHistory(new SearchHistoryEntity
                                                            {
                                                                Text = category.Name,
                                                                Link = category.ToUICategoryModels(null).InnerLink
                                                            });
            }
            if (category.ParentId == 0)
            {
                return View("CategoriesList", models);
            }
            else
            {
                return View("CategoriesDetails", models);
            }
        }
    }
}